import socket, struct

username = "SeR"
verification_key = "verification_key"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # boilerplate
s.connect(("192.168.0.100", 25565))  # adjust accordingly

# now for the packet
# note that the String type is specified as having a length of 64, we'll pad that

packet = ""

packet += struct.pack("B", 1)  # packet type
packet += struct.pack("B", 7)  # protocol version
packet += "%-64s" % username  # magic!
packet += "%-64s" % verification_key
packet += struct.pack("B", 0)  # that unused byte, assuming a NULL byte here

# send what we've crafted
s.send(packet)

#The "%-20s" may be weird for you if you've never used format strings. Essentially..
print "%s" % 5

#.. would print out 5 ..
print "%10s" % 5

#.. would pad the output to be exactly 10 characters in width. But it pads them on the right side, we want that padding on the left -- hence the - ..
print "%-10s" % s, "<this will be 9 spaces away from the '5'>"
